package com.electric.service.impl;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.electric.entity.Customer;
import com.electric.mapper.CustomerMapper;
import com.electric.service.ICustomerService;

/**
 * <p>
 * 客户 服务实现类
 * </p>
 *
 * @author zhangbin
 * @since 2018-08-28
 */
@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements ICustomerService {

	public Page<Customer> selectPage(int pageNum,int pageSize, String keyword) {
		EntityWrapper<Customer> searchWrapper = new EntityWrapper<Customer>();
		if(StringUtils.isNotBlank(keyword)) {
			searchWrapper.like("customer_number", keyword).or().like("customer_name", keyword);
		}
		searchWrapper.orderBy("customer_number",true);
		
		Page<Customer> page = new Page<Customer>(pageNum, pageSize);
		
		page = selectPage(page, searchWrapper);
		
		return page;
	}

	public boolean checkCustomerNumber(String customerNumber, String seqId) {
		EntityWrapper<Customer> wrapper = new EntityWrapper<Customer>();
		
		wrapper.eq("customer_number", customerNumber);
		if(StringUtils.isNotBlank(seqId)) {
			wrapper.ne("seq_id", seqId);
		}
		
		int selectCount = selectCount(wrapper);
		
		return selectCount > 0;
	}

}
